package com.sect.edu.info.manager.controller;

import com.sect.edu.info.manager.domain.Teacher;
import com.sect.edu.info.manager.service.TeacherService;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author げっしょく
 * @date 2021/7/19
 */
public class TeacherController {
    TeacherService teacherService = new TeacherService();
    Scanner sc = new Scanner(System.in);
    public void exit() {
        int a =0;
        while (true) {
            System.out.println("欢迎使用老师管理系统");
            System.out.println("1. 添加老师  2. 删除老师  3.修改老师信息  4. 查看老师信息  5. 退出 ");
            System.out.println("请输入：");
            a = sc.nextInt();
            switch (a) {
                case 1 :
                    //添加老师
                    addTeacher();
                    break ;
                case 2 :
                    //删除老师
                    deleteTea();
                    break ;
                case 3 :
                    //修改老师
                    break ;
                case 4 :
                    //查看老师
                    AllLookTeacher();
                    break ;
                case 5 :
                    //退出
                    break ;
                default:
                    System.out.println("还未开放本功能；请重新选择：");
            }
        }

    }

    private void AllLookTeacher() {
        ArrayList<Teacher> t = teacherService.returnList();
        if(t.size() == 0){
            System.out.println("你的系统中还没有信息");
            return ;
        }
        System.out.println("老师工号\t老师姓名\t老师生日\t老师年龄");
        for (int i = 0; i < t.size(); i++) {
            Teacher tea = t.get(i);
            System.out.println(tea.getId()+"\t"+tea.getName()+"\t"+tea.getBirthday()+"\t"+tea.getAge());
        }
    }

    private void deleteTea() {
        String id;
        System.out.println("请输入老师的工号");
        id = sc.next();
        boolean result = teacherService.judgId(id);
        if (result) {
            teacherService.delTeacher(id);
            System.out.println("删除成功！");
        }else{
            System.out.println("删除失败，没有找到该工号！！");
        }
    }

    private void addTeacher() {
        String id;
        while (true) {
            System.out.println("请输入老师的工号：");
            id = sc.next();
            boolean flag = judgeId(id);
            if (flag) {
                System.out.println("该工号已存在，请重新输入");
            }else{
                break ;
            }
        }
        System.out.println("请输入老师的姓名：");
        String name = sc.next();
        System.out.println("请输入老师的生日：");
        String brithday = sc.next();
        System.out.println("请输入老师的年龄：");
        int age = sc.nextInt();
        Teacher teacher = new Teacher(id ,name , brithday , age);
        boolean reasult = teacherService.addteacher(teacher);
        if (reasult) {
            System.out.println("添加成功");
        }else{
            System.out.println("添加失败");
        }
    }

    private boolean judgeId(String id) {
        return teacherService.judgId(id);
    }
}
